package com.starbooks.tmail.service.impl;

import com.starbooks.tmail.service.ActiveMqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

@Service
public class ActiveMqServiceImpl implements ActiveMqService {

  @Autowired
  private JmsTemplate jmsTemplate;

  @Override
  public void sendMessage(String message) {
    System.out.println("发送消息：【" + message + "】");

    // 在默认的情况下，JmsTemplate会提供一个SimpleMessageConverter去提供转换规则，它实现了MessageConverter接口

    jmsTemplate.convertAndSend(message);
    // jmsTemplate.convertAndSend(address, message);
  }

  //JmsListener注解 监听地址发送过来的消息

  @Override
  @JmsListener(destination = "${spring.jms.template.default-destination}")
  public void receiveMessage(String message) {
    System.out.println("接收到消息：【" + message + "】");
  }
}
